package com.north.light.androidutils.viewshot;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;

import com.north.light.androidutils.R;
import com.north.light.androidutils.log.LogUtil;

/**
 * 截图
 */
public class ViewShotActivity extends AppCompatActivity {

    private static final String TAG = ViewShotActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_shot);
        Button snap = findViewById(R.id.btSnap);
        NestedScrollView nsView = findViewById(R.id.nsView);
        LinearLayout llView = findViewById(R.id.llView);
        TextView tvTitle1 = findViewById(R.id.tvTitle1);
        ViewShotStringRecyclerView rvString = findViewById(R.id.rvString);
        rvString.initData();


        ImageView ivSnapResult = findViewById(R.id.ivSnapResult);
        snap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //开始截图--普通截图
                ViewShotUtils.viewSnapShot(nsView, new ViewShotUtils.ViewSnapListener() {
                    @Override
                    public void success(Bitmap bitmap) {
                        LogUtil.d(TAG, "生成了bitmap");
                        ivSnapResult.setImageBitmap(bitmap);
                    }

                    @Override
                    public void failed(String message) {
                        LogUtil.d(TAG, message);
                    }
                });
            }
        });
    }
}